package com.chinasoft.book.app;

import com.chinasoft.book.mapper.BookMapper;
import com.chinasoft.book.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BaseConfigMain {

    public static void main(String[] args) {
        ApplicationContext ioc = new ClassPathXmlApplicationContext("base_config.xml");

        BookMapper mapper = ioc.getBean("mapper", BookMapper.class);
        System.out.println(mapper.selectById(100));

        BookMapper mapper2 = ioc.getBean("bookMapperImpl", BookMapper.class);
        System.out.println(mapper2.selectById(100));

        System.out.println(mapper == mapper2);

        BookService bookService = ioc.getBean("service", BookService.class);
        bookService.queryBook();
        System.out.println("===============scope 测试=========");

        // 测试单例对象
        BookMapper bookMapper1 = ioc.getBean("bookMapper2", BookMapper.class);
        BookMapper bookMapper2 = ioc.getBean("bookMapper2", BookMapper.class);

        System.out.println(bookMapper1 == bookMapper2);
        bookMapper1.selectById(10);
        bookMapper2.selectById(10);


    }
}
